
import os
import time
import random
import subprocess
# import uiautomator2 as u2

#解锁手机
def toLock():
    #唤醒屏幕
    os.system("adb shell input keyevent 26")
    time.sleep(1)
    #上划显示输入密码页面
    os.system("adb shell input swipe 100 950 315 540 100")
    time.sleep(2)
    #输入密码
    os.system("adb shell input text 125800")
    return

#自动刷视频
def watchVideo():
    # 定义重复执行的次数
    repeat_times = 500

    # 循环执行ADB指令
    for i in range(repeat_times):

        print(f"This is the {i+1} execution")

        x1 = random.randint(560, 750)
        y1 = random.randint(1700, 1800)
        x2 = random.randint(780, 900)
        y2 = random.randint(1300, 1400) 
        


        x1_ = random.randint(110, 130)
        y1_ = random.randint(950, 970)
        x2_ = random.randint(315, 330)
        y2_ = random.randint(540, 560) 


        times = random.randint(100, 200) 

        os.system("adb shell input swipe " + str(x1) + " " + str(y1) + " " + str(x2) + " " + str(y2) + " " + str(times))

        # os.system("adb shell input swipe " + str(x1_) + " " + str(y1_) + " " + str(x2_) + " " + str(y2_) + " " + str(times))

        #随机秒数
        r_seconds = random.randint(1, 10)

        time.sleep(r_seconds)

        clik_love = random.randint(1, 1000)

        if clik_love > 9500:
            #adb  shell input tap 988 1288
            click_x = random.randint(977, 998)
            click_y = random.randint(1245, 1260)
            os.system("adb shell input tap " + str(click_x) + " " + str(click_y))
            time.sleep(random.randint(2, 4))

    print("execution finish") 

#自动刷视频 今日头条视频
def watchVideo2():
    # 定义重复执行的次数
    repeat_times = 500

    # 循环执行ADB指令
    for i in range(repeat_times):

        print(f"This is the {i+1} execution")

        x1 = random.randint(560, 750)
        y1 = random.randint(1850, 1950)
        x2 = random.randint(780, 900)
        y2 = random.randint(1300, 1400) 
        


        x1_ = random.randint(110, 130)
        y1_ = random.randint(950, 970)
        x2_ = random.randint(315, 330)
        y2_ = random.randint(540, 560) 


        times = random.randint(100, 200) 

        os.system("adb shell input swipe " + str(x1) + " " + str(y1) + " " + str(x2) + " " + str(y2) + " " + str(times))

        # os.system("adb shell input swipe " + str(x1_) + " " + str(y1_) + " " + str(x2_) + " " + str(y2_) + " " + str(times))

        #随机秒数
        r_seconds = random.randint(1, 10)

        time.sleep(r_seconds)

        clik_love = random.randint(1, 1000)

        if clik_love > 920:
            #adb  shell input tap 988 1288
            click_x = random.randint(977, 988)
            click_y = random.randint(1265, 1280)
            os.system("adb shell input tap " + str(click_x) + " " + str(click_y))
            time.sleep(random.randint(2, 4))

    print("execution finish") 

#自动刷新闻 头条
def watchNews():
    # 定义重复执行的次数
    repeat_times = 1000

    clik_love = 100
    clik_no_love = 100
    
    # 循环执行ADB指令
    for i in range(repeat_times):

        print(f"This is the {i+1} execution")

        x1 = random.randint(560, 750)
        y1 = random.randint(1650, 1750)
        x2 = random.randint(780, 900)
        y2 = random.randint(1200, 1300) 


        times = random.randint(100, 200) 

        os.system("adb shell input swipe " + str(x1) + " " + str(y1) + " " + str(x2) + " " + str(y2) + " " + str(times))

        # os.system("adb shell input swipe " + str(x1_) + " " + str(y1_) + " " + str(x2_) + " " + str(y2_) + " " + str(times))

        #随机秒数
        r_seconds = random.randint(1, 5)

        time.sleep(r_seconds)

        clik_love = random.randint(1, 1000)

        if clik_no_love <= 700 and clik_love > 600:
            #adb  shell input tap 988 1288
            click_x = random.randint(500, 600)
            click_y = random.randint(1000, 1300)
            os.system("adb shell input tap " + str(click_x) + " " + str(click_y))
            time.sleep(random.randint(1, 3))


        clik_no_love = random.randint(1, 1000)


        if clik_no_love > 700:
            #adb  shell input tap 988 1288
            click_x = random.randint(500, 600)
            click_y = random.randint(900, 1200)
            os.system("adb shell input keyevent 4")
            clik_no_love = 100
            time.sleep(random.randint(1, 2))
            

    print("execution finish") 


#打开某个app
# def openApp(name):
#    # 连接到已经开启了开发者模式并且通过USB调试连接到电脑的安卓设备
#    d = u2.connect()
#    # 打开指定的应用，这里的'com.example.app'是应用的包名
#    d.app_start('com.example.app')


#头条看广告
def watchAnAdvertisement():
     # 定义重复执行的次数
    repeat_times = 20

    # 循环执行ADB指令
    for i in range(repeat_times):

        print(f"This is the {i+1} execution")

        x1 = random.randint(840, 850)
        y1 = random.randint(190, 200)
        time.sleep(30)
        os.system("adb shell input tap " + str(x1) + " " + str(y1))

        time.sleep(random.randint(2, 4))

        x2 = random.randint(340, 680)
        y2 = random.randint(1290, 1390)
        os.system("adb shell input tap " + str(x2) + " " + str(y2))
        
#自动刷小说
def watchFiction(): 
    # 定义重复执行的次数
    repeat_times = 500

    # 循环执行ADB指令
    for i in range(repeat_times):

        print(f"This is the {i+1} execution")

        x2 = random.randint(400, 500)
        y2 = random.randint(1700, 1800)
        x1 = random.randint(780, 900)
        y1 = random.randint(1300, 1400) 


        times = random.randint(100, 200) 

        os.system("adb shell input swipe " + str(x1) + " " + str(y1) + " " + str(x2) + " " + str(y2) + " " + str(times))

        #随机秒数
        r_seconds = random.randint(1, 6)

        time.sleep(r_seconds)


    print("execution finish") 


# watchVideo()
# watchVideo2()
watchNews()    
# watchAnAdvertisement()
# watchFiction()